﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace Tnelab.MBWrapper
{
    public enum MouseFlags
    {
        LBUTTON = 0x01,
        RBUTTON = 0x02,
        SHIFT = 0x04,
        CONTROL = 0x08,
        MBUTTON = 0x10,
    }
    public enum KeyFlags
    {
        EXTENDED = 0x0100,
        REPEAT = 0x4000,
    }
    public enum MouseMsg
    {
        MOUSEMOVE = 0x0200,
        LBUTTONDOWN = 0x0201,
        LBUTTONUP = 0x0202,
        LBUTTONDBLCLK = 0x0203,
        RBUTTONDOWN = 0x0204,
        RBUTTONUP = 0x0205,
        RBUTTONDBLCLK = 0x0206,
        MBUTTONDOWN = 0x0207,
        MBUTTONUP = 0x0208,
        MBUTTONDBLCLK = 0x0209,
        MOUSEWHEEL = 0x020A,
    }
    public enum CursorType
    {
        Pointer,
        Cross,
        Hand,
        IBeam,
        Wait,
        Help,
        EastResize,
        NorthResize,
        NorthEastResize,
        NorthWestResize,
        SouthResize,
        SouthEastResize,
        SouthWestResize,
        WestResize,
        NorthSouthResize,
        EastWestResize,
        NorthEastSouthWestResize,
        NorthWestSouthEastResize,
        ColumnResize,
        RowResize,
        MiddlePanning,
        EastPanning,
        NorthPanning,
        NorthEastPanning,
        NorthWestPanning,
        SouthPanning,
        SouthEastPanning,
        SouthWestPanning,
        WestPanning,
        Move,
        VerticalText,
        Cell,
        ContextMenu,
        Alias,
        Progress,
        NoDrop,
        Copy,
        None,
        NotAllowed,
        ZoomIn,
        ZoomOut,
        Grab,
        Grabbing,
        Custom
    }
    public class JsCallNativeEventArg : EventArgs
    {
        public IntPtr WebView { get; internal set; }
        public Int64 CallId { get; internal set; }
        public int MessageId { get; internal set; }
        public string Request { get; internal set; }
        public string Func { get; internal set; }
    }
    public class Rect
    {
        public int X { get; set; }
        public int Y { get; set; }
        public int Width { get; set; }
        public int Height { get; set; }
    }
    public class PaintBitUpdatedEventArg : EventArgs
    {
        public IWebViewBase WebView { get; internal set; }
        //public object Param { get; internal set; }
        public byte[] Buffer { get; internal set; }
        public Rect Rect { get; internal set; }
        public int Width { get; internal set; }
        public int Height { get; internal set; }
    }
    public class Size
    {
        public int Width { get; set; }
        public int Height { get; set; }
        public Size(int width, int height)
        {
            this.Width = width;
            this.Height = height;
        }
    }
    public class LoadUrlBeginArgs : EventArgs
    {
        public IWebViewBase WebView { get; internal set; }
        public Uri Url  { get; internal set; }
        /// <summary>
        /// 可以用任意位置html填充
        /// </summary>
        public IList<byte> Datas { get; internal set; }
    }
    public class LoadUrlEndArgs : EventArgs
    {
        public Uri Url { get; internal set; }
        public IWebViewBase WebView { get; internal set; }
        /// <summary>
        /// 可以修改传回的html内容
        /// </summary>
        public IList<byte> Datas { get; internal set; }
        public bool NeedUpdate { get; internal set; }
    }
    public interface IWebViewBase:IDisposable
    {
        event EventHandler<LoadUrlBeginArgs> LoadUrlBegin;
        event EventHandler<LoadUrlEndArgs> LoadUrlEnd;
        event EventHandler<PaintBitUpdatedEventArg> PaintBitUpdated;
        bool LoadUrlEndEnable { get; set; }
        bool Transparent { get; set; }
        void LoadUrl(Uri url);
        bool IsVip { get; }
        Size Size { get; }
        void Resize(int width, int height);
        bool FireKeyDownEvent(uint virtualKeyCode, uint flags, bool systemKey);
        bool FireKeyUpEvent(uint virtualKeyCode, uint flags, bool systemKey);
        void SetFocus();
        void KillFocus();
        bool FireKeyPressEvent(uint virtualKeyCode, uint flags, bool systemKey);
        bool FireMouseWheelEvent(int x, int y, int delta, uint flags);
        bool FireMouseEvent(uint message, int x, int y, uint flags);
        CursorType GetCursorType();
        Action<Action> UIInvoke { get; }
    }
    public interface IWebView : IWebViewBase
    {
        event EventHandler<JsCallNativeEventArg> JsCallNative;
        Task<string> RunJsAsync(string script);
        void ResponseJsCallNative(Int64 callId, int messageId, string response);
        internal void JsExecStateInvoke(Action<IntPtr> action);
    }
    public interface IServiceWebView : IWebViewBase
    {
        internal Task<string> RunJsAsync(string script);
    }
}
